from pattern.circuit import Control

class entry(Control):
    
    VERBS = ["Clear"]
    
    def realize(self, event):
        self.realized = event
        if not hasattr(event.shape, 'store'):
            event.shape.store = { }
        self.updated(event)
    
    def incoming(self, event):
        request, = event.data
        print request
        try:
            name, value = request.strip().split('=', 1)
            self.realized.shape.store[name] = value
            self.updated(event)
        except ValueError:
            pass

    def please(self, event):
        return self.realized.shape.store

    def verb(self, event):
        self.realized.shape.store = { }
        self.updated(event)

    def updated(self, event):
        bridge = self.acquireInterface(event, "Storage")
        if bridge is not None:
            bridge.push(self)

    def __repr__(self): return `self.realized.shape.store`
